package com.winit.tree.repository;

import com.winit.tree.model.TreeNode;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface TreeRepository extends CrudRepository<TreeNode, String> {

    List<TreeNode> findByLevel(String level);

    List<TreeNode> findByParentIdAndIsDelAndType(String parentId, String isDel, String type);

    @Query(value = "SELECT * FROM  matrix_tree WHERE parent_id = ?1 AND is_del=?2 ORDER BY FIND_IN_SET(id, ?3) ASC ", nativeQuery = true)
    List<TreeNode> findByParentIdAndIsDel(String parentId, String isDel,String childSort);

    List<TreeNode> findByParentIdAndIsDel(String parentId, String isDel);

    List<TreeNode> findByParentId(String parentId);

    List<TreeNode> findByTypeAndIsDelNot(String type, String isDel);
}
